//
//  SAMemberCelebrateVC.m
//  saasRetail
//
//  Created by mac on 2023/6/4.
//

#import "SAMemberCelebrateVC.h"
#import "UILabel+NSMutableAttributedString.h"
#import "BubbleTableView.h"
#import "SAMemberOptionModel.h"
#import "SAMemberOptionAPI.h"
#import "HDDatePickerView.h"
#import "SASmsSendAPI.h"

@interface SAMemberCelebrateVC ()<HTTPAPIDelegate, UITextFieldDelegate>

@property (nonatomic, strong) UILabel *typeLab;
@property (nonatomic, strong) UILabel *sendMemberLab;
@property (nonatomic, strong) UIButton *allMemberBtn;
@property (nonatomic, strong) UIButton *surplusBtn;//剩余会员
@property (nonatomic, strong) UILabel *surplusNumLab;
@property (nonatomic, strong) UIButton *surplusNumBtn;

@property (nonatomic, strong) UILabel *surplusLab;
@property (nonatomic, strong) UIButton *selectBtn;
@property (nonatomic, strong) UILabel *selectLab;
@property (nonatomic, strong) UIButton *vipTypeBtn;//会员类型

@property (nonatomic, strong) UILabel *scopeLab;
@property (nonatomic, strong) UILabel *anniversaryLab;
@property (nonatomic, strong) UITextField *anniversaryNumTf;
@property (nonatomic, strong) UILabel *anniversaryYLab;

@property (nonatomic, strong) UILabel *activitiesLab;
@property (nonatomic, strong) UIButton *dateBtn;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIButton *timeBtn;

@property (nonatomic, strong) UILabel *discountLab;
@property (nonatomic, strong) UITextField *discountNumTf;
@property (nonatomic, strong) UILabel *discountCodeLab;

@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UIView *grayView;
@property (nonatomic, strong) UILabel *informationLab;

@property (nonatomic, strong) UILabel *tipTitleLab;
@property (nonatomic, strong) UILabel *tipLab;

@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, strong) UIButton *confirmationBtn;
@property (nonatomic, strong) BubbleTableView *memberBubbleView;
@property (nonatomic, strong) NSMutableArray<SAMemberOptionModel *> *memberMarr;
@property (nonatomic, strong) SAMemberOptionAPI *memberOptionAPI;
@property (nonatomic, assign) NSInteger memberRow;
@property (nonatomic, strong) NSDateFormatter *dateFormatter;
@property (nonatomic, strong) BubbleTableView *yearBubbleView;
@property (nonatomic, assign) NSInteger yearRow;
@property (nonatomic, strong) SASmsSendAPI *smsSendAPI;

@end

@implementation SAMemberCelebrateVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - HTTPAPIDelegate
- (void)fetchData:(id)data fromServerSuccessedWithAPI:(HTTPAPI *)api {
    
    if (self.memberOptionAPI == api) {
        self.memberMarr = [SAMemberOptionModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
        if (self.memberMarr.count > 0) {
            self.selectLab.text = [NSString stringWithFormat:@"  %@",self.memberMarr.firstObject.name];
        }
    }else if (self.smsSendAPI == api) {
        [Prompt popPromptViewWithMsg:@"发送成功" duration:3];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)fetchDataFromServerFailedWithError:(NSError *)error API:(HTTPAPI *)api {
    
}

#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (string.length == 0) {
        return YES;
    }
    if (textField.text.length > 2){
        return NO;
    }
    NSString *newStr = [NSString stringWithFormat:@"%@%@",textField.text,string];
    if (newStr.doubleValue > 100) {
        return NO;
    }
    return [self validateNumber:string];
}

- (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}

-(void)textFieldDidEndEditing:(UITextField *)textField {
    [self updateInformation];
}

#pragma mark - event
-(void)clickedAllMemberBtn:(UIButton *)sender {
    self.allMemberBtn.selected = YES;
    self.surplusBtn.selected = NO;
    self.selectBtn.selected = NO;
}

-(void)clickedSurplusBtn:(UIButton *)sender {
    self.allMemberBtn.selected = NO;
    self.surplusBtn.selected = YES;
    self.selectBtn.selected = NO;
}

-(void)clickedSelectBtn:(UIButton *)sender {
    self.allMemberBtn.selected = NO;
    self.surplusBtn.selected = NO;
    self.selectBtn.selected = YES;
}

//超过多少月vip
-(void)clickedSurplusNumBtn:(UIButton *)sender {
    NSMutableArray *marr = [NSMutableArray array];
    for (int i = 1; i < 37; i++) {
        [marr addObject:[NSString stringWithFormat:@"%d",i]];
    }
    
    NSInteger height = marr.count * 50 + 10;
    if (height > 190) {
        height = 190;
    }
    NSArray *arr = nil;
    UIView *window = [UIApplication sharedApplication].keyWindow;
    if (!self.yearBubbleView) {
        self.yearBubbleView = [[BubbleTableView alloc] initWithLocation:(BubbleLocationDown) bubbleAlignment:(BubbleAlignmentRight) width:120 height:height cellClickBlock:^(NSInteger row, NSString * _Nonnull rowString, NSArray *fromDataArray) {
            self.yearRow = row;
            self.surplusNumLab.text = [NSString stringWithFormat:@"  %@",rowString];
        } hideBlock:^{
            self.yearBubbleView = nil;
        }];
        
        [self.yearBubbleView showWithTargetView:self.surplusLab maskSuperView:window];
        [self.yearBubbleView updateBubble:marr fromDataArray:arr];// 更新气泡弹框
        self.yearBubbleView.bubbleCellHeight = 50;
        self.yearBubbleView.selectRow = self.yearRow;
        self.yearBubbleView.isBubbleScrollEnabled = YES;
        self.yearBubbleView.bubbleCellTextAlignment = NSTextAlignmentCenter;
    }
}

-(void)clickedAllowBtn {
    NSMutableArray *marr = [NSMutableArray array];
    for (SAMemberOptionModel *model in self.memberMarr) {
        if (model.name.length == 0) {
            model.name = @"";
        }
        [marr addObject:model.name];
    }
    
    NSInteger height = marr.count * 50 + 10;
    if (height > 190) {
        height = 190;
    }
    NSArray *arr = nil;
    UIView *window = [UIApplication sharedApplication].keyWindow;
    if (!self.memberBubbleView) {
        self.memberBubbleView = [[BubbleTableView alloc] initWithLocation:(BubbleLocationDown) bubbleAlignment:(BubbleAlignmentRight) width:120 height:height cellClickBlock:^(NSInteger row, NSString * _Nonnull rowString, NSArray *fromDataArray) {
            self.memberRow = row;
            self.selectLab.text = [NSString stringWithFormat:@"  %@",rowString];
        } hideBlock:^{
            self.memberBubbleView = nil;
        }];
        
        [self.memberBubbleView showWithTargetView:self.vipTypeBtn maskSuperView:window];
        [self.memberBubbleView updateBubble:marr fromDataArray:arr];// 更新气泡弹框
        self.memberBubbleView.bubbleCellHeight = 50;
        self.memberBubbleView.selectRow = self.memberRow;
        self.memberBubbleView.isBubbleScrollEnabled = YES;
        self.memberBubbleView.bubbleCellTextAlignment = NSTextAlignmentCenter;
    }
}

- (void)clickStartDateBtn:(UIButton *)btn {
    WeakSelf
    HDDatePickerView *pickerView = [[HDDatePickerView alloc] initWithSlectedDate:self.dateBtn.titleLabel.text];
    [pickerView show];
    pickerView.selectDateBlock = ^(NSString *selectedDate) {
        NSDate *date1 = [self.dateFormatter dateFromString:selectedDate];
        NSDate *date2 = [self.dateFormatter dateFromString:weakSelf.timeBtn.titleLabel.text];
        if ([date1 compare:date2] == NSOrderedDescending) {
            [Prompt popPromptViewWithMsg:@"开始日期不能大于截止日期" duration:2];
        }else {
            [self.dateBtn setTitle:selectedDate forState:UIControlStateNormal];
            [self updateInformation];
        }
    };
}

- (void)clickEndDateBtn:(UIButton *)btn {
    WeakSelf
    HDDatePickerView *pickerView = [[HDDatePickerView alloc] initWithSlectedDate:self.timeBtn.titleLabel.text];
    [pickerView show];
    pickerView.selectDateBlock = ^(NSString *selectedDate) {
        NSDate *date1 = [self.dateFormatter dateFromString:selectedDate];
        NSDate *date2 = [self.dateFormatter dateFromString:weakSelf.dateBtn.titleLabel.text];
        if ([date1 compare:date2] == NSOrderedAscending) {
            [Prompt popPromptViewWithMsg:@"截止日期不能小于开始日期" duration:2];
        }else {
            [self.timeBtn setTitle:selectedDate forState:UIControlStateNormal];
            [self updateInformation];
        }
    };
}

- (void)clickedCancelBtn:(UIButton *)btn {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickedConfirmationBtn:(UIButton *)btn {
    
    [self.view endEditing:YES];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认立即群发短信吗？" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
        [self confirmation];
    }];
    UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:true completion:nil];
}

- (void)confirmation {
    self.smsSendAPI.inactiveMonth = [NSString stringWithFormat:@"%zd",self.yearRow + 1];
    self.smsSendAPI.memberLevel = self.memberMarr[self.memberRow].id;
    if (self.allMemberBtn.selected == YES) {
        self.smsSendAPI.targetType = @"1";
    }else if (self.surplusBtn.selected == YES) {
        self.smsSendAPI.targetType = @"2";
    }else {
        self.smsSendAPI.targetType = @"3";
    }
    self.smsSendAPI.tempId = self.tempId;
    
    NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
    mdic[@"discountRate"] = [NSString stringWithFormat:@"%0.1lf",[self.discountNumTf.text doubleValue] / 10];
    mdic[@"startDate"] = self.dateBtn.titleLabel.text;
    mdic[@"endDate"] = self.timeBtn.titleLabel.text;
    mdic[@"year"] = self.anniversaryNumTf.text;
    self.smsSendAPI.templateParams = mdic;
    
    [self.smsSendAPI sendRequestToServerWithActivityViewAndMask:POST];
}

-(void)updateInformation {
    
//    _informationLab.text = @"尊敬的Alina小店店铺会员，感恩一起走过的时光，我们的5年，2022-01-01到2022-01-05迎来周年店庆，全场88折起，期待您的光临。";
    
    NSString *title1 = @"尊敬的";
    NSString *title2 = [SAValueManger shareInStance].userInfo.storeName;
    NSString *title3 = @"店铺会员，感恩一起走过的时光，我们的";
    NSString *title4 = self.anniversaryNumTf.text;
    NSString *title5 = @"年，";
    NSString *title6 = self.dateBtn.titleLabel.text;
    NSString *title7 = @"到";
    NSString *title8 = self.timeBtn.titleLabel.text;
    NSString *title9 = @"迎来周年店庆，全场";
    NSString *title10 = [NSString stringWithFormat:@"%0.1lf",[self.discountNumTf.text doubleValue] / 10];
    NSString *title11 = @"折起，期待您的光临。";
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];
    
    NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:title1];
    [str1 addAttribute:NSForegroundColorAttributeName value:kGrayColor range: NSMakeRange(0, title1.length)];
    [attributedString appendAttributedString:str1];
    
    NSMutableAttributedString *str2 = [[NSMutableAttributedString alloc] initWithString:title2];
    [str2 addAttribute:NSForegroundColorAttributeName value:kRedColor range: NSMakeRange(0, title2.length)];
    [attributedString appendAttributedString:str2];
    
    NSMutableAttributedString *str3 = [[NSMutableAttributedString alloc] initWithString:title3];
    [str3 addAttribute:NSForegroundColorAttributeName value:kGrayColor range: NSMakeRange(0, title3.length)];
    [attributedString appendAttributedString:str3];
    
    NSMutableAttributedString *str4 = [[NSMutableAttributedString alloc] initWithString:title4];
    [str4 addAttribute:NSForegroundColorAttributeName value:kRedColor range: NSMakeRange(0, title4.length)];
    [attributedString appendAttributedString:str4];
    
    NSMutableAttributedString *str5 = [[NSMutableAttributedString alloc] initWithString:title5];
    [str5 addAttribute:NSForegroundColorAttributeName value:kGrayColor range: NSMakeRange(0, title5.length)];
    [attributedString appendAttributedString:str5];
    
    NSMutableAttributedString *str6 = [[NSMutableAttributedString alloc] initWithString:title6];
    [str6 addAttribute:NSForegroundColorAttributeName value:kRedColor range: NSMakeRange(0, title6.length)];
    [attributedString appendAttributedString:str6];
    
    NSMutableAttributedString *str7 = [[NSMutableAttributedString alloc] initWithString:title7];
    [str7 addAttribute:NSForegroundColorAttributeName value:kGrayColor range: NSMakeRange(0, title7.length)];
    [attributedString appendAttributedString:str7];
    
    NSMutableAttributedString *str8 = [[NSMutableAttributedString alloc] initWithString:title8];
    [str8 addAttribute:NSForegroundColorAttributeName value:kRedColor range: NSMakeRange(0, title8.length)];
    [attributedString appendAttributedString:str8];
    
    NSMutableAttributedString *str9 = [[NSMutableAttributedString alloc] initWithString:title9];
    [str9 addAttribute:NSForegroundColorAttributeName value:kGrayColor range: NSMakeRange(0, title9.length)];
    [attributedString appendAttributedString:str9];
    
    NSMutableAttributedString *str10 = [[NSMutableAttributedString alloc] initWithString:title10];
    [str10 addAttribute:NSForegroundColorAttributeName value:kRedColor range: NSMakeRange(0, title10.length)];
    [attributedString appendAttributedString:str10];
    
    NSMutableAttributedString *str11 = [[NSMutableAttributedString alloc] initWithString:title11];
    [str11 addAttribute:NSForegroundColorAttributeName value:kGrayColor range: NSMakeRange(0, title11.length)];
    [attributedString appendAttributedString:str11];
    
    self.informationLab.attributedText = attributedString;
}

#pragma mark - initUI
-(void)initUI {
    
    [self setNavigationItemBackBBIAndTitle:@"店庆活动设置"];
    [self setBgImage:nil];
    self.view.backgroundColor = kBgColor;
    
    [self.view addSubview:self.typeLab];
    [self.view addSubview:self.sendMemberLab];
    [self.view addSubview:self.allMemberBtn];
    [self.view addSubview:self.surplusBtn];
    [self.view addSubview:self.surplusNumLab];
    [self.view addSubview:self.surplusNumBtn];
    [self.view addSubview:self.surplusLab];
    [self.view addSubview:self.selectBtn];
    [self.view addSubview:self.selectLab];
    [self.view addSubview:self.vipTypeBtn];
    
    [self.view addSubview:self.scopeLab];
    [self.view addSubview:self.anniversaryLab];
    [self.view addSubview:self.anniversaryNumTf];
    [self.view addSubview:self.anniversaryYLab];
    
    [self.view addSubview:self.activitiesLab];
    [self.view addSubview:self.dateBtn];
    [self.view addSubview:self.line];
    [self.view addSubview:self.timeBtn];
    
    [self.view addSubview:self.discountLab];
    [self.view addSubview:self.discountNumTf];
    [self.view addSubview:self.discountCodeLab];
    
    [self.view addSubview:self.contentLab];
    [self.view addSubview:self.grayView];
    [self.grayView addSubview:self.informationLab];
    
    [self.view addSubview:self.tipTitleLab];
    [self.view addSubview:self.tipLab];
    
    [self.view addSubview:self.cancelBtn];
    [self.view addSubview:self.confirmationBtn];
    
    self.allMemberBtn.selected = YES;
    
    [self.typeLab setAttributedStringWithSubString:@"店庆活动" font:kBFont(15)];
    [self.informationLab setLineSpace:5];
    [self.tipTitleLab setLineSpace:10];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *timeFormatStr = [dateFormatter stringFromDate:[NSDate date]];
    [self.dateBtn setTitle:timeFormatStr forState:UIControlStateNormal];
    [self.timeBtn setTitle:timeFormatStr forState:UIControlStateNormal];
    
    [self.memberOptionAPI sendRequestToServerWithActivityViewAndMask:GET];
    
    [self updateInformation];
}

-(UILabel *)typeLab {
    if (!_typeLab) {
        _typeLab = [[UILabel alloc] initWithFrame:SARectMake(10, StatusHeight + 15, 200, 15)];
        _typeLab.font = kFont(15);
        _typeLab.textColor = kBlackColor;
        _typeLab.text = @"短信类型： 店庆活动";
    }
    return _typeLab;
}

-(UILabel *)sendMemberLab {
    if (!_sendMemberLab) {
        _sendMemberLab = [[UILabel alloc] initWithFrame:SARectMake(10, StatusHeight + 45, 100, 15)];
        _sendMemberLab.font = kFont(15);
        _sendMemberLab.textColor = kBlackColor;
        _sendMemberLab.text = @"发送会员：";
    }
    return _sendMemberLab;
}

-(UIButton *)allMemberBtn {
    if (!_allMemberBtn) {
        _allMemberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _allMemberBtn.frame = SARectMake(88, StatusHeight + 35, 120, 35);
        [_allMemberBtn setImage:[UIImage imageNamed:@"button_unchecked"] forState:UIControlStateNormal];
        [_allMemberBtn setImage:[UIImage imageNamed:@"button_checked"] forState:UIControlStateSelected];
        [_allMemberBtn setTitle:@"  全部会员" forState:UIControlStateNormal];
        [_allMemberBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        _allMemberBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_allMemberBtn addTarget:self action:@selector(clickedAllMemberBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _allMemberBtn;
}

-(UIButton *)surplusBtn {
    if (!_surplusBtn) {
        _surplusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _surplusBtn.frame = SARectMake(88, StatusHeight + 70, 70, 35);
        [_surplusBtn setImage:[UIImage imageNamed:@"button_unchecked"] forState:UIControlStateNormal];
        [_surplusBtn setImage:[UIImage imageNamed:@"button_checked"] forState:UIControlStateSelected];
        [_surplusBtn setTitle:@"  超过" forState:UIControlStateNormal];
        [_surplusBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        _surplusBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_surplusBtn addTarget:self action:@selector(clickedSurplusBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _surplusBtn;
}

-(UILabel *)surplusNumLab {
    if (!_surplusNumLab) {
        _surplusNumLab = [[UILabel alloc] initWithFrame:SARectMake(155, StatusHeight + 75, 50, 25)];
        _surplusNumLab.font = kFont(15);
        _surplusNumLab.textColor = kBlackColor;
        _surplusNumLab.text = @"  1";
        _surplusNumLab.textAlignment = NSTextAlignmentLeft;
        _surplusNumLab.layer.cornerRadius = kScaleNum(3);
        _surplusNumLab.layer.masksToBounds = YES;
        _surplusNumLab.layer.borderColor = kLightgGrayColor.CGColor;
        _surplusNumLab.layer.borderWidth = kScaleNum(1);
    }
    return _surplusNumLab;
}

-(UIButton *)surplusNumBtn {
    if (!_surplusNumBtn) {
        _surplusNumBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _surplusNumBtn.frame = SARectMake(155, StatusHeight + 75, 50, 25);
        [_surplusNumBtn setImage:[UIImage imageNamed:@"down_arrow"] forState:UIControlStateNormal];
        _surplusNumBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _surplusNumBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
        [_surplusNumBtn addTarget:self action:@selector(clickedSurplusNumBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _surplusNumBtn;
}

-(UILabel *)surplusLab {
    if (!_surplusLab) {
        _surplusLab = [[UILabel alloc] initWithFrame:SARectMake(208, StatusHeight + 75, 150, 25)];
        _surplusLab.font = kFont(15);
        _surplusLab.textColor = kBlackColor;
        _surplusLab.text = @"个月未消费会员";
        _surplusLab.textAlignment = NSTextAlignmentLeft;
    }
    return _surplusLab;
}

-(UIButton *)selectBtn {
    if (!_selectBtn) {
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _selectBtn.frame = SARectMake(88, StatusHeight + 105, 87, 35);
        [_selectBtn setImage:[UIImage imageNamed:@"button_unchecked"] forState:UIControlStateNormal];
        [_selectBtn setImage:[UIImage imageNamed:@"button_checked"] forState:UIControlStateSelected];
        [_selectBtn setTitle:@"  发送给" forState:UIControlStateNormal];
        [_selectBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        _selectBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_selectBtn addTarget:self action:@selector(clickedSelectBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectBtn;
}

-(UILabel *)selectLab {
    if (!_selectLab) {
        _selectLab = [[UILabel alloc] initWithFrame:SARectMake(172, StatusHeight + 110, 120, 25)];
        _selectLab.font = kFont(15);
        _selectLab.textColor = kBlackColor;
        _selectLab.text = @" 普通会员";
        _selectLab.textAlignment = NSTextAlignmentLeft;
        _selectLab.layer.cornerRadius = kScaleNum(3);
        _selectLab.layer.masksToBounds = YES;
        _selectLab.layer.borderColor = kLightgGrayColor.CGColor;
        _selectLab.layer.borderWidth = kScaleNum(1);
    }
    return _selectLab;
}

-(UIButton *)vipTypeBtn {
    if (!_vipTypeBtn) {
        _vipTypeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _vipTypeBtn.frame = SARectMake(172, StatusHeight + 110, 120, 25);
        [_vipTypeBtn setImage:[UIImage imageNamed:@"down_arrow"] forState:UIControlStateNormal];
        _vipTypeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _vipTypeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
        [_vipTypeBtn addTarget:self action:@selector(clickedAllowBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _vipTypeBtn;
}

-(UILabel *)scopeLab {
    if (!_scopeLab) {
        _scopeLab = [[UILabel alloc] initWithFrame:SARectMake(10, StatusHeight + 155, 200, 15)];
        _scopeLab.font = kFont(15);
        _scopeLab.textColor = kBlackColor;
        _scopeLab.text = @"活动范围： ";
    }
    return _scopeLab;
}

-(UILabel *)anniversaryLab {
    if (!_anniversaryLab) {
        _anniversaryLab = [[UILabel alloc] initWithFrame:SARectMake(0, StatusHeight + 180, 90, 30)];
        _anniversaryLab.font = kFont(15);
        _anniversaryLab.textColor = kBlackColor;
        _anniversaryLab.text = @"周年";
        _anniversaryLab.textAlignment = NSTextAlignmentRight;
    }
    return _anniversaryLab;
}

-(UITextField *)anniversaryNumTf {
    if (!_anniversaryNumTf) {
        _anniversaryNumTf = [[UITextField alloc] initWithFrame:SARectMake(95, StatusHeight + 180, 80, 30)];
        _anniversaryNumTf.font = kFont(15);
        _anniversaryNumTf.textColor = kBlackColor;
        _anniversaryNumTf.text = @"1";
        _anniversaryNumTf.textAlignment = NSTextAlignmentCenter;
        _anniversaryNumTf.layer.cornerRadius = kScaleNum(3);
        _anniversaryNumTf.layer.masksToBounds = YES;
        _anniversaryNumTf.layer.borderColor = kLightgGrayColor.CGColor;
        _anniversaryNumTf.layer.borderWidth = kScaleNum(1);
        _anniversaryNumTf.clearButtonMode = UITextFieldViewModeWhileEditing;
        _anniversaryNumTf.delegate = self;
        _anniversaryNumTf.keyboardType = UIKeyboardTypeDecimalPad;
    }
    return _anniversaryNumTf;
}

-(UILabel *)anniversaryYLab {
    if (!_anniversaryYLab) {
        _anniversaryYLab = [[UILabel alloc] initWithFrame:SARectMake(180, StatusHeight + 180, 80, 30)];
        _anniversaryYLab.font = kFont(15);
        _anniversaryYLab.textColor = kBlackColor;
        _anniversaryYLab.text = @"年";
    }
    return _anniversaryYLab;
}

-(UILabel *)activitiesLab {
    if (!_activitiesLab) {
        _activitiesLab = [[UILabel alloc] initWithFrame:SARectMake(0, StatusHeight + 220, 90, 30)];
        _activitiesLab.font = kFont(15);
        _activitiesLab.textColor = kBlackColor;
        _activitiesLab.text = @"活动时间";
        _activitiesLab.textAlignment = NSTextAlignmentRight;
    }
    return _activitiesLab;
}

-(UIButton *)dateBtn {
    if (!_dateBtn) {
        _dateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _dateBtn.frame = SARectMake(95, StatusHeight + 220, 118, 30);
        [_dateBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        _dateBtn.titleLabel.font = kFont(18);
        _dateBtn.layer.cornerRadius = 5;
        _dateBtn.layer.masksToBounds = YES;
        _dateBtn.layer.borderColor = kColor(180, 180, 180, 1.f).CGColor;
        _dateBtn.layer.borderWidth = 1;
        [_dateBtn addTarget:self action:@selector(clickStartDateBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _dateBtn;
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIImageView alloc] initWithFrame:SARectMake(223, StatusHeight + 241, 6, 2)];
        _line.backgroundColor = kBlackColor;
        _line.layer.cornerRadius = kScaleNum(1);
        _line.layer.masksToBounds = YES;
    }
    return _line;
}

-(UIButton *)timeBtn {
    if (!_timeBtn) {
        _timeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _timeBtn.frame = SARectMake(239, StatusHeight + 220, 118, 30);
        [_timeBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        _timeBtn.titleLabel.font = kFont(18);
        _timeBtn.layer.cornerRadius = 5;
        _timeBtn.layer.masksToBounds = YES;
        _timeBtn.layer.borderColor = kColor(180, 180, 180, 1.f).CGColor;
        _timeBtn.layer.borderWidth = 1;
        [_timeBtn addTarget:self action:@selector(clickEndDateBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _timeBtn;
}

-(UILabel *)discountLab {
    if (!_discountLab) {
        _discountLab = [[UILabel alloc] initWithFrame:SARectMake(0, StatusHeight + 260, 90, 30)];
        _discountLab.font = kFont(15);
        _discountLab.textColor = kBlackColor;
        _discountLab.text = @"折扣";
        _discountLab.textAlignment = NSTextAlignmentRight;
    }
    return _discountLab;
}

-(UITextField *)discountNumTf {
    if (!_discountNumTf) {
        _discountNumTf = [[UITextField alloc] initWithFrame:SARectMake(95, StatusHeight + 260, 80, 30)];
        _discountNumTf.font = kFont(15);
        _discountNumTf.textColor = kBlackColor;
        _discountNumTf.text = @"88";
        _discountNumTf.textAlignment = NSTextAlignmentCenter;
        _discountNumTf.layer.cornerRadius = kScaleNum(3);
        _discountNumTf.layer.masksToBounds = YES;
        _discountNumTf.layer.borderColor = kLightgGrayColor.CGColor;
        _discountNumTf.layer.borderWidth = kScaleNum(1);
        _discountNumTf.delegate = self;
        _discountNumTf.keyboardType = UIKeyboardTypeDecimalPad;
    }
    return _discountNumTf;
}

-(UILabel *)discountCodeLab {
    if (!_discountCodeLab) {
        _discountCodeLab = [[UILabel alloc] initWithFrame:SARectMake(180, StatusHeight + 260, 80, 30)];
        _discountCodeLab.font = kFont(15);
        _discountCodeLab.textColor = kBlackColor;
        _discountCodeLab.text = @"%";
    }
    return _discountCodeLab;
}

-(UILabel *)contentLab {
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] initWithFrame:SARectMake(10, StatusHeight + 315, 200, 15)];
        _contentLab.font = kFont(15);
        _contentLab.textColor = kBlackColor;
        _contentLab.text = @"短信内容（例）：";
    }
    return _contentLab;
}

-(UIView *)grayView {
    if (!_grayView) {
        _grayView = [[UIImageView alloc] initWithFrame:SARectMake(20, StatusHeight + 340, kBaseScreenWidth - 40, 70)];
        _grayView.userInteractionEnabled = YES;
        _grayView.layer.borderColor = kLightgGrayColor.CGColor;
        _grayView.layer.borderWidth = kScaleNum(1);
        _grayView.layer.cornerRadius = kScaleNum(5);
        _grayView.layer.masksToBounds = YES;
    }
    return _grayView;
}

-(UILabel *)informationLab {
    if (!_informationLab) {
        _informationLab = [[UILabel alloc] initWithFrame:SARectMake(8, 0, kBaseScreenWidth - 56, 70)];
        _informationLab.font = kFont(13);
        _informationLab.textColor = kGrayColor;
        _informationLab.text = @"尊敬的Alina小店店铺会员，感恩一起走过的时光，我们的5年，2022-01-01到2022-01-05迎来周年店庆，全场88折起，期待您的光临。";
        _informationLab.numberOfLines = 0;
    }
    return _informationLab;
}

-(UILabel *)tipLab {
    if (!_tipLab) {
        _tipLab = [[UILabel alloc] initWithFrame:SARectMake(10, StatusHeight + 440, 200, 15)];
        _tipLab.font = kFont(15);
        _tipLab.textColor = kBlackColor;
        _tipLab.text = @"提示： ";
    }
    return _tipLab;
}

-(UILabel *)tipTitleLab {
    if (!_tipTitleLab) {
        _tipTitleLab = [[UILabel alloc] initWithFrame:SARectMake(30, StatusHeight + 465, kBaseScreenWidth, 45)];
        _tipTitleLab.font = kFont(14);
        _tipTitleLab.textColor = kBlackColor;
        _tipTitleLab.text = @"1、请核对并确认短信内容，发送后将无法撤回；\n2、客户设置短信拦截无法接收短信，平台概不负责；";
        _tipTitleLab.numberOfLines = 0;
    }
    return _tipTitleLab;
}

-(UIButton *)cancelBtn {
    if (!_cancelBtn) {
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelBtn.frame = SARectMake(60, StatusHeight + 540, 100, 36);
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:kLightgGrayColor forState:UIControlStateNormal];
        _cancelBtn.titleLabel.font = kFont(18);
        _cancelBtn.layer.borderColor = kLightgGrayColor.CGColor;
        _cancelBtn.layer.borderWidth = kScaleNum(1);
        _cancelBtn.layer.cornerRadius = kScaleNum(5);
        _cancelBtn.layer.masksToBounds = YES;
        [_cancelBtn addTarget:self action:@selector(clickedCancelBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}

-(UIButton *)confirmationBtn {
    if (!_confirmationBtn) {
        _confirmationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _confirmationBtn.frame = SARectMake(kBaseScreenWidth - 160, StatusHeight + 540, 100, 36);
        [_confirmationBtn setTitle:@"确认" forState:UIControlStateNormal];
        [_confirmationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _confirmationBtn.titleLabel.font = kFont(18);
        _confirmationBtn.backgroundColor = kBuleColor;
        _confirmationBtn.layer.cornerRadius = kScaleNum(5);
        _confirmationBtn.layer.masksToBounds = YES;
        [_confirmationBtn addTarget:self action:@selector(clickedConfirmationBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmationBtn;
}

-(NSMutableArray<SAMemberOptionModel *> *)memberMarr {
    if (!_memberMarr) {
        _memberMarr = [NSMutableArray array];
    }
    return _memberMarr;
}

-(SAMemberOptionAPI *)memberOptionAPI {
    if (!_memberOptionAPI) {
        _memberOptionAPI = [SAMemberOptionAPI apiWithDelegate:self];
    }
    return _memberOptionAPI;
}

-(NSDateFormatter *)dateFormatter {
    if (!_dateFormatter) {
        _dateFormatter = [NSDateFormatter new];
        [_dateFormatter setDateFormat:@"yyyy-MM-dd"];
    }
    return _dateFormatter;
}

-(SASmsSendAPI *)smsSendAPI {
    if (!_smsSendAPI) {
        _smsSendAPI = [SASmsSendAPI apiWithDelegate:self];
    }
    return _smsSendAPI;
}


@end
